﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for XLDL
/// </summary>
public class DataProvidier
{
    static string strsql = ConfigurationManager.ConnectionStrings["Ketnoi"].ConnectionString.ToString();
    public static DataTable Docbang(string LenhSQL)
    {
        using (SqlConnection cnn = new SqlConnection(strsql))
        {
            SqlDataAdapter bodocghi = new SqlDataAdapter(LenhSQL, cnn);
            DataTable bang = new DataTable();
            bodocghi.Fill(bang);
            return bang;
        }
    }
    public static void Thuchienlenh(string LenhSQL)
    {
        using (SqlConnection cnn = new SqlConnection(strsql))
        {
            cnn.Open();
            SqlCommand bolenh = new SqlCommand(LenhSQL, cnn);
            bolenh.ExecuteNonQuery();
            cnn.Close();
        }
    }
    public static string getdata(string LenhSQL)
    {
        using (SqlConnection cnn = new SqlConnection(strsql))
        {
            cnn.Open();
            SqlCommand cmd = cnn.CreateCommand();
            cmd.CommandText = LenhSQL;
            string result = "" + cmd.ExecuteScalar();
            cnn.Close();
            return result;

        }
    }
    public int quyen(string uers)
    {
        using (SqlConnection cnn = new SqlConnection(strsql))
        {
            cnn.Open();
            SqlCommand cmd = new SqlCommand("Select ma_quyen from nguoi_dung where ten_dang_nhap='" + uers + "'", cnn);
            int maquyen = (int)cmd.ExecuteScalar();
            cnn.Close();
            return maquyen;
        }
    }
}